#!/usr/bin/env node

const http = require('https'),
      log = console.log,
      add = 'https://maoyan.com/films?showType=1',
      cheerio = require('cheerio'),
      fs = require('fs');
      //url = require('url');

let movielist=[];
http.get(add,(res)=>{
  let data = '';

  res.on('data',(chunk)=>{data += chunk;});

  res.on('end',()=>{


    let $ = cheerio.load(data);
    let courses = $('body').find('div.movie-item-title>a');
    let score = $('body').find('div.channel-detail-orange'); 
    log(data);
    log(courses.length);
    for(let i = 0;i<courses.length;i++){
      log('hello');
      let movies = {
        movieId:'',
        movieName:'',
        movieRange:''
      }

      let num = $(courses[i]).attr('href').lastIndexOf('/');
      movies.movieName = $(courses[i]).text();
      movies.movieId = $(courses[i]).attr('href').substring(num+1);
      movies.movieRange = $(score[i]).text();

      movielist[i] = movies;


    }
    //log(movielist);
  })

})


